﻿using System.Configuration;
using System.Linq;
using HelperTools;

namespace Framework.Email.Configuration
{
    public class EmailTemplatesCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new EmailTemplateElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((EmailTemplateElement) element).Key;
        }

        public EmailTemplateElement this[int index]
        {
            get { return (EmailTemplateElement)BaseGet(index); }
        }

        public new EmailTemplateElement this[string key]
        {
            get
            {
                return
                    (from EmailTemplateElement element in this select element).FirstOrDefault(
                        el => el.With(x => x.Key).Returns(y => y.Equals(key), false));
            }
        }
    }
}
